public class Demo {
    public static final int COUNT = 20_0000_0000;

    public static void fun1() {

        long end = System.currentTimeMillis();

        int a = 0;
        for (long i = 0; i < COUNT; i++) {
            a++;
        }

        a = 0;
        for (long i = 0; i < COUNT; i++) {
            a++;
        }

        long beg = System.currentTimeMillis();

        System.out.println("单线程消耗的时间是:" + (beg - end) + "ms");
    }

    public static void fun2() {

        long beg = System.currentTimeMillis();

        Thread t = new Thread(() -> {
            int a = 0;
            for (long i = 0; i < COUNT; i++) {
                a++;
            }
        });

        Thread t1 = new Thread(() -> {
            int a = 0;
            for (long i = 0; i < COUNT; i++) {
                a++;
            }
        });

        t.start();
        t1.start();

        try {
            t.join(); //join           等待当前线程结束在执行主线程
            t1.join();//join           等待当前线程结束在执行主线程
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        long end = System.currentTimeMillis();
        System.out.println("多线程消耗的时间:" + (end - beg) + "ms");
    }
    public static void main(String[] args) {
        //单线程消耗的时间
        fun1();
        //多线程消耗的时间
        fun2();

    }
}
